package com.eastedu.common.thread;

import cn.hutool.core.thread.NamedThreadFactory;

import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
 * The type Task executor.
 *
 * @author superman
 */
public class TaskExecutor {
    private static final Executor executorService = new ScheduledThreadPoolExecutor(5, new NamedThreadFactory("task-executor", false));


    /**
     * Execute.
     *
     * @param runnable the runnable
     *
     * @param async    the async
     */
    public static void execute(Runnable runnable, boolean async) {
        if (async) {
            executorService.execute(runnable);
        } else {
            runnable.run();
        }
    }
}
